package demo;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class GetNameRandom {
    public static void main(String[] args) throws IOException {
        //随机点名
        //1.获取到数据集合
        BufferedReader br = new BufferedReader(new FileReader("IOTest\\names.txt"));
        //2.打乱集合
        ArrayList<String> list = new ArrayList<>();
        String len;
        while ((len = (br.readLine())) != null) {
            String str = len.split("-")[0];
            list.add(str);
        }
        br.close();
        //3.抽取数据
        Collections.shuffle(list);
        System.out.println(list.get(0));
    }
}
